<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑价格</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var priceType = new Ext.form.TextField({
          fieldLabel: '价格类型',
          allowBlank: false,
          readOnly: true,
          name: 'sub_type',
          anchor: '90%'
        });

        var price = new Ext.form.TextField({
          fieldLabel: '价格',
          allowBlank: false,
          name: 'price',
          anchor: '90%'
        });

        var priceId = new Ext.form.Hidden({
          name: 'id'
        });
        
        //提交按钮
        var editPriceButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            editPriceButton.setDisabled(true);
            if (editPriceFormPanel.form.isValid()) {
              editPriceFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    editPriceWin.destroy();
                    priceDS.reload();
                  } else {
                    Ext.MessageBox.alert('消息', resp.result.info);
                    editPriceButton.enable();
                  }
                },
                failure: function(result, request){
                  editPriceButton.enable();
                  Ext.MessageBox.alert('消息', '服务器的通信失败!');
                }
              });
            }
            else {
              editPriceButton.enable();
              //Ext.MessageBox.alert('输入验证有错', '请输入必输选项');
            }
          }
        })
        
        var editPriceFormPanel = new Ext.form.FormPanel({
          labelWidth: 65,
          width: '200',
          labelAlign: 'right',
          frame : true,
          url: '/price/updatePrice',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'price'
            }, {
              name: 'sub_type'
            }]),
          items: [priceType,price,priceId],
          buttons: [editPriceButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                editPriceWin.destroy();
              }
            }]
        });
        editPriceFormPanel.render('edit_price_form');
        
        editPriceFormPanel.form.load({
          url: '/price/getPriceById?price_id=<%=@priceId%>',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        
      })
    </script>
    <div id="edit_price_form"></div>
  </body>
</html>